﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoPro.Provisioning;

namespace CoPro.Local
{
    public abstract class AbstractLocalProvider : ILocalProvider
    {
        public abstract IContentLocal GetLocal();

        /// <summary>
        /// This implementation of <code>GetNextLocal</code> does a simple fallback logic that goes from the regional 
        /// language format, to the normal language, to the fallback
        /// </summary>
        /// <param name="_currentLocal">The current local that was not feasible.</param>
        /// <returns>Next local to try, if there are no more locals to try, null is returned.</returns>
        public virtual IContentLocal GetNextLocal(IContentLocal _currentLocal)
        {
            //if it is the default local, return null because there won't be another local to try
            if (_currentLocal.IsDefault)
                return null;


            String[] splittedLocal = _currentLocal.LocalAbbreviation.Split('-');
            //check - was in the string because this indicates that we can try the neutral local
            //otherwise use DefaultLocal
            if (splittedLocal.Length == 2)
            {
                return new ContentLocal(splittedLocal[0]);
            }
            else
            {
                return CoProManager.Current.DefaultLocal;
            }
        }

    }
}
